package manage.modules.rbac.util;

import java.util.ArrayList;
import java.util.List;

import manage.modules.menu.model.Menu;
import manage.modules.menu.model.MenuFolders;
import manage.modules.rbac.model.ActionOfRole;

import org.springframework.util.CollectionUtils;

/**
 * 
 * Description：权限相关工具类
 * 
 * @since 2012-9-16 上午9:56:25
 * @author dongji
 * 
 */
public final class RBACUtil {

	/**
	 * 处理菜单封装类为ids，方便工具类 对权限处理
	 * 
	 * @param menuFolders
	 *            封装的MenuFolders
	 * @return 所有菜单的id集合
	 */
	public static List<Integer> processMFToIdList(List<MenuFolders> menuFolders) {
		if (CollectionUtils.isEmpty(menuFolders)) {
			return null;
		}
		List<Integer> ids = new ArrayList<Integer>();
		for (MenuFolders menuFolder : menuFolders) {
			ids.add(menuFolder.getMenu().getMenuId());
			for (Menu menu : menuFolder.getChilds()) {
				ids.add(menu.getMenuId());
			}
		}
		return ids;
	}

	/**
	 * 处理ActionOfRole为ids
	 * 
	 * @param actionOfRoles
	 * @return
	 */
	public static List<Integer> processARToIdList(
			List<ActionOfRole> actionOfRoles) {
		if (CollectionUtils.isEmpty(actionOfRoles)) {
			return null;
		}
		List<Integer> ids = new ArrayList<Integer>();
		for (ActionOfRole actionOfRole : actionOfRoles) {
			ids.add(actionOfRole.getActionId());
		}
		return ids;
	}
}
